﻿#region Copyright 
/*-------------------------------------------------------------------------
* 命名空间名称/文件名:    SSPivot.Common.Cache/CacheExtensions 
* CLR版本:     4.0.30319.42000
* 机器名称:    DESKTOP-NHMLO8A
* 功 能：       N/A
* 类 名：       CacheExtensions
* 创建时间：  2025/5/23 17:20:49
* 版本号：      v1.0
* 创建人:        xulong
*-------------------------------------------------------------------------*/
#endregion
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using SSPivot.Common.Cache;
using SSPivot.Common.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class CacheExtensions
    {
        public static IServiceCollection AddSSPivotCache(this IServiceCollection services,IConfiguration configuration)
        {
            var config = configuration.GetSection("Cache").Get<CacheConfig>();// ConfigHelper.GetOptions<CacheConfig>("CacheConfig");

            SSPivot.Common.Cache.CacheManager.Initialize(new CacheConfig
            {
                Mode = config.Mode,
                RedisConnection = config.RedisConnection
            });
            services.AddSingleton<ICacheService>(SSPivot.Common.Cache.CacheManager.Instance);
            
            return services;
        }
    }
}
